import os
import sys
import time
from selenium.webdriver.common.by import By
from Base.base_action import BaseAction


class SendContent(BaseAction):
    # 通用按钮
    swipe_loc = (500, 1500, 420, 500)
    go_look = (By.ID, "org.c2h4.afei.beauty:id/ll_go_look")  # 前往查看按钮
    product_loc = (By.ID, "org.c2h4.afei.beauty:id/iv_product")  # 产品按钮
    used = (By.XPATH, "//*[contains(@text, '用过')]")  # 用过
    my_comment = (By.XPATH, "//*[contains(@text, '我的评分')]")  # 我的评分
    five_star = (By.ID, "org.c2h4.afei.beauty:id/iv_star5")  # 5星
    assess = (By.ID, "org.c2h4.afei.beauty:id/et_assess")  # 评论输入框
    finish = (By.ID, "org.c2h4.afei.beauty:id/tv_finish")  # 完成

    # 查产品相关按钮
    search_pro = (By.XPATH, "//*[contains(@text, '查产品')]")  # 查产品
    input_text = (By.ID, "org.c2h4.afei.beauty:id/et_container")  # 搜索输入框
    search_word = "雅诗兰黛"
    evaluate = "自动化测试自动化测试自动化测试自动化测试！"
    # 护肤榜相关按钮
    spr_btn = (By.XPATH, "//*[contains(@text, '护肤榜')]")  # 护肤榜
    add_picture = (By.ID, "org.c2h4.afei.beauty:id/iv_add")  # 添加图片
    # 美妆榜相关按钮
    makeup_btn = (By.XPATH, "//*[contains(@text, '美妆榜')]")  # 美妆榜
    # 品牌库相关按钮
    brand_lib = (By.XPATH, "//*[contains(@text, '品牌库')]")  # 品牌库
    themes = (By.ID, "org.c2h4.afei.beauty:id/iv_banner")  # 品牌主题馆
    enter_brand = (By.ID, "org.c2h4.afei.beauty:id/ll_go_brand")  # 进入品牌按钮
    shop_name = (By.ID, "org.c2h4.afei.beauty:id/tv_shop_name")  # 店铺名位置
    # 福利情报局相关按钮
    welfare = (By.XPATH, "//*[contains(@text, '福利情报局')]")  # 福利情报局
    comment_area = (By.XPATH, "//*[contains(@text, '评论区')]")  # 评论区
    comment = (By.ID, "org.c2h4.afei.beauty:id/et_comment")  # 评论框
    submit = (By.ID, "org.c2h4.afei.beauty:id/tv_comment")  # 评论按钮
    # 主页文章评论
    ll_comment = (By.ID, "org.c2h4.afei.beauty:id/ll_comment")  # 主页文章评论按键

    # 聊
    community = (By.ID, "org.c2h4.afei.beauty:id/tv_community")  # 聊
    topic = (By.ID, "org.c2h4.afei.beauty:id/tv_desc")  # 话题按钮
    post_posts = (By.XPATH, "//*[contains(@text, '发布帖子')]")
    add_pic = (By.ID, "org.c2h4.afei.beauty:id/iv_pic")  # 添加图片
    et_content = (By.ID, "org.c2h4.afei.beauty:id/et_content")  # 内容输入框
    release = (By.ID, "org.c2h4.afei.beauty:id/rl_release")  # 发布

    # 图片评论相关
    picture_add = (By.ID, "org.c2h4.afei.beauty:id/check")  # 图片选择
    picture_confirm = (By.ID, "org.c2h4.afei.beauty:id/picture_tv_ok")  # 图片确认
    picture_crop = (By.ID, "org.c2h4.afei.beauty:id/menu_crop")  # 图片裁剪

    # 从查产品发送内容
    def search_product_send(self):
        self.click_element(self.search_pro)
        self.click_element(self.input_text)
        self.input_keys(self.input_text, self.search_word)
        w, h = self.get_window_size()
        self.tab(x=w - 30, y=h - 30)
        self.click_element(self.product_loc)
        time.sleep(2)
        try:
            self.click_element(self.used)
        except:
            self.click_element(self.my_comment)
        self.click_element(self.five_star)
        self.input_keys(self.assess, self.evaluate)
        self.click_element(self.finish)
        time.sleep(2)
        self.swipe(*self.swipe_loc)
        file_name = sys._getframe().f_code.co_name
        time_stamp = str(time.time()).split(".")[0]
        time.sleep(5)
        self.screen_shot(r"D:\app_auto_test\ScreenShot" + os.sep + file_name + time_stamp + ".png")

    # 从护肤榜发送内容
    def skin_pro_rank_send(self):
        self.click_element(self.spr_btn)
        self.tab(ele=self.find_elements(self.product_loc)[0])
        time.sleep(2)
        try:
            self.click_element(self.used)
        except:
            self.click_element(self.my_comment)
        self.click_element(self.five_star)
        self.input_keys(self.assess, self.evaluate)
        self.click_element(self.finish)
        time.sleep(2)
        self.swipe(*self.swipe_loc)
        file_name = sys._getframe().f_code.co_name
        time_stamp = str(time.time()).split(".")[0]
        time.sleep(5)
        self.screen_shot(r"D:\app_auto_test\ScreenShot" + os.sep + file_name + time_stamp + ".png")

    # 从美妆榜发送内容
    def makeup_rank_send(self):
        self.click_element(self.makeup_btn)
        self.tab(ele=self.find_elements(self.product_loc)[0])
        time.sleep(2)
        try:
            self.click_element(self.used)
        except:
            self.click_element(self.my_comment)
        self.click_element(self.five_star)
        self.input_keys(self.assess, self.evaluate)
        self.click_element(self.finish)
        time.sleep(2)
        self.swipe(*self.swipe_loc)
        file_name = sys._getframe().f_code.co_name
        time_stamp = str(time.time()).split(".")[0]
        time.sleep(5)
        self.screen_shot(r"D:\app_auto_test\ScreenShot" + os.sep + file_name + time_stamp + ".png")

    # 从品牌库发送内容
    def brand_library_send(self):
        self.click_element(self.brand_lib)
        self.tab(ele=self.find_elements(self.themes)[0])
        self.tab(ele=self.find_elements(self.enter_brand)[0])
        time.sleep(20)
        while True:
            try:
                self.tab(ele=self.find_elements(self.product_loc)[0])
                break
            except:
                self.swipe(*self.swipe_loc)
        try:
            self.click_element(self.used)
        except:
            self.click_element(self.my_comment)
        self.click_element(self.five_star)
        self.input_keys(self.assess, self.evaluate)
        self.click_element(self.finish)
        time.sleep(2)
        self.swipe(*self.swipe_loc)
        file_name = sys._getframe().f_code.co_name
        time_stamp = str(time.time()).split(".")[0]
        time.sleep(5)
        self.screen_shot(r"D:\app_auto_test\ScreenShot" + os.sep + file_name + time_stamp + ".png")

    # 从福利情发送内容
    def welfare_intelligence_bureau_send(self):
        self.click_element(self.welfare)
        self.click_element(self.comment_area)
        self.input_keys(self.comment, self.evaluate)
        self.click_element(self.submit)

    # 从首页文章发送内容
    def home_page_article_send(self):
        time.sleep(10)
        self.swipe(*self.swipe_loc)
        time.sleep(2)
        self.click_element(self.ll_comment)
        self.input_keys(self.comment, self.evaluate)
        self.find_elements(self.submit)[-1].click()
        file_name = sys._getframe().f_code.co_name
        time_stamp = str(time.time()).split(".")[0]
        time.sleep(5)
        self.screen_shot(r"D:\app_auto_test\ScreenShot" + os.sep + file_name + time_stamp + ".png")

    # 发送图片评论
    def send_picture_from_comment(self):
        self.click_element(self.spr_btn)
        self.tab(ele=self.find_elements(self.product_loc)[0])
        time.sleep(2)
        try:
            self.click_element(self.used)
        except:
            self.click_element(self.my_comment)
        self.click_element(self.five_star)
        self.input_keys(self.assess, self.evaluate)
        for i in range(4):
            self.click_element(self.add_picture)
            pictures = self.find_elements(self.picture_add)
            pictures[i].click()
            self.click_element(self.picture_confirm)
            self.click_element(self.picture_crop)
        self.click_element(self.finish)
        time.sleep(2)
        self.swipe(*self.swipe_loc)
        file_name = sys._getframe().f_code.co_name
        time_stamp = str(time.time()).split(".")[0]
        time.sleep(5)
        self.screen_shot(r"D:\app_auto_test\ScreenShot" + os.sep + file_name + time_stamp + ".png")

    # 从聊的热门话题中发送图片帖子
    def send_post_picture(self):
        self.click_element(self.community)
        self.click_element(self.topic)
        self.click_element(self.post_posts)
        self.click_element(self.add_pic)
        self.click_element(self.picture_add)
        self.click_element(self.picture_confirm)
        self.click_element(self.picture_crop)
        self.input_keys(self.et_content, self.evaluate)
        self.click_element(self.release)
        file_name = sys._getframe().f_code.co_name
        time_stamp = str(time.time()).split(".")[0]
        time.sleep(5)
        self.screen_shot(r"D:\app_auto_test\ScreenShot" + os.sep + file_name + time_stamp + ".png")
